/*
 * IOStream.h
 *
 *  Created on: Mar 22, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef IOSTREAM_H_
#define IOSTREAM_H_

#ifndef PH_H_
#include "ph.h"
#endif

#include <boost/array.hpp>
#include <string>

#ifndef AESSWITCHENCRYPTER_H_
#include "Cuda_AES/AesSwitchEncrypter.h"
#endif



class IOStream
{
public:
    IOStream(const std::string& file, AesSwitchEncrypter& e);
    //IOStream(const std::string& file);
    IOStream(uint32_t maxCacheSize, const std::string& file, AesSwitchEncrypter& e);
    ~IOStream();

    uint32_t getLenght();
    void setLenght(uint32_t len);
    void setPos(uint32_t pos);
    uint32_t getPos();

    void readRange(void* buffer, uint32_t begin, uint32_t end);
    void writeRange(const void* buffer, uint32_t begin, uint32_t end);

private:
    std::string d_file;
    boost::array<byte, 1024> d_memory;
    bool d_cacheFile;
    uint32_t d_maxCacheSize;
    FILE* fp;

    AesSwitchEncrypter& d_encrypter;
    std::vector<byte> d_writeBuffer;
};

#endif /* IOSTREAM_H_ */
